<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>修改密码</title>
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <link rel="stylesheet" href="plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="css/style.css">
</head>
<body>
    <div id="app">
        <div class="content-header">
            <h1>密码<small>修改密码</small></h1>
<!--            <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">-->
<!--                <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>-->
<!--                <el-breadcrumb-item>管理</el-breadcrumb-item>-->
<!--                <el-breadcrumb-item>密码管理</el-breadcrumb-item>-->
<!--            </el-breadcrumb>-->
        </div>
        <div class="box" style="padding-left: 500px">
            <el-form :model="admin" ref="ruleForm" label-width="100px">
                <p></p>
                <el-form-item label="用户名" prop="loginName">
                    {{admin.loginName}}
                </el-form-item>
                <el-form-item label="旧密码" prop="password">
                    <el-input style="width: 300px" v-model="admin.password"></el-input>
                </el-form-item>
                <el-form-item label="新密码">
                    <el-input style="width: 300px" v-model="pojo.password"></el-input>
                </el-form-item>
                <el-form-item label="确认新密码">
                    <el-input style="width: 300px" v-model="newPass"></el-input>
                </el-form-item>
            </el-form>
            <div style="margin-left: 150px">
                <el-button type="primary" @click="save()">保存</el-button>
                <el-button type="danger" @click="goLast()">返回</el-button>
            </div>
        </div>
    </div>
</body>
<script src="/js/vue.js"></script>
<script src="/js/axios.js"></script>
<script src="/js/elementui.js"></script>
<script src="/js/util.js"></script>
<script>
    new Vue({
        el: '#app',
        // router,
        data() {
            return {
                loginName:'',
                pojo:'',
                newPassword:'',
                newPass:'',
                admin:''
            }
        },
        created() {
            this.loginName = getQueryString("loginName");
            this.findByName();
        },
        methods: {
            goLast(){
                location.href="main.html";
            },
            save(){
              if(this.pojo.password==this.newPass){
                this.pojo.admin=this.admin;
                debugger;
                  axios.post(`/admin/updatePassword.do`,this.pojo).then(response => {
                      //console.log(response.data);
                  }).catch(error=>{
                      console.log(error);
                  })
              } else {
                  console.log("新密码不一致，错误！！！")
              }
            },
            findByName(){
                axios.get(`/admin/findByName.do?name=${this.loginName}`).then(response => {
                    this.pojo = response.data;
                    this.admin=this.pojo.admin;
                    this.admin.password='';
                    debugger;
                })
            }
        }
    })
</script>
</html>